import requests
from bs4 import BeautifulSoup
from lxml import etree
import chardet


def test():
    header = {"User-Agent": "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko"}
    r = requests.get("https://www.westnovel.com/Album/", headers=header)
    r.encoding = chardet.detect(r.content)['encoding']
    html = etree.HTML(r.text)
    # tostring 中文乱码解决方案
    # result = etree.tostring(html, encoding="utf-8").decode("utf-8")
    result = etree.tostring(html)
    bs = BeautifulSoup(result, "lxml", from_encoding="utf-8")
    array = bs.findAll("dd")
    for i in array:
        print("详情地址是%s,小说标题是%s" % (i.a['href'], i.string))
    # print(result)
